import { FieldOption, type FormType, IBaseModel, IFormData } from 'easy-descriptor'
import { TableColumn, TableExpandColumn, TableSelectionColumn } from 'naive-ui/es/data-table/src/interface'
import {
  CascaderProps,
  CheckboxProps,
  DatePickerProps,
  FormInst,
  FormItemGiProps,
  FormItemRule,
  InputGroupProps,
  InputNumberProps,
  InputProps,
  RadioProps,
  RateProps,
  SelectProps,
  SliderProps,
  SwitchProps,
  TimePickerProps,
  TreeSelectProps,
  UploadProps
} from 'naive-ui'
import { Ref } from 'vue'

export interface RuleHandler<T extends IBaseModel<T> = IBaseModel<any>> {
  (parma: { key: DataKey; formData: Ref<IFormData<T> | undefined>; formType: FormType }): FormItemRule[]
}

interface FormItemProps<T extends IBaseModel<T> = IBaseModel<any>> extends FormItemGiProps {
  ruleHandler?: RuleHandler<T>
}

type NaiveInputProps =
  | InputProps
  | CheckboxProps
  | RadioProps
  | CascaderProps
  | DatePickerProps
  | TimePickerProps
  | UploadProps
  | InputNumberProps
  | SliderProps
  | RateProps
  | SwitchProps
  | SelectProps
  | TreeSelectProps
  | InputGroupProps

type FormCompProps = NaiveInputProps & Record<string, any>

export type EzFieldOption<T extends IBaseModel<T> = IBaseModel<any>> = FieldOption &
  Omit<TableColumn, 'key' | 'type'> & {
    path?: string
    key?: DataKey
    type?: TableSelectionColumn['type'] | TableExpandColumn['type'] | 'index' | never
    formItemProps?: FormItemProps<T>
    formCompProps?: FormCompProps
  }
